package com.core.aspectj.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class AspectjPermissionActivity extends Activity {


    public  static void start(Activity activity, List<String> list) {
            Intent i = new Intent(activity,AspectjPermissionActivity.class);
            ArrayList<String> array = new ArrayList(list);
            i.putStringArrayListExtra(KEY_LIST,array);
            activity.startActivity(i);
    }
    private String TAG="PermissionActivity";
    private static final String KEY_LIST = "__LIST";
    private final int REQUEST_CODE = 303;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG,"onCreate");
        Intent intent = getIntent();
        List<String> list = intent.getStringArrayListExtra(KEY_LIST);
        if (list != null) {
            String args[] = new String[list.size()];
            list.toArray(args);
            ActivityCompat.requestPermissions(this, args, REQUEST_CODE);
        } else {
            finish();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        Log.i(TAG,"onRequestPermissionsResult->requestCode="+requestCode);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        finish();
    }
}
